import smtplib
from email.mime.text import MIMEText
import os
from email.mime.multipart import MIMEMultipart


email_body='''
<h1 align="center">接口自动化测试报告</h1>
<p align="center">详情见附件</p>
'''
html_file_path=os.path.join(os.path.dirname(__file__),'..','html_reports','WX_API_TEST_V1.6','WX_API_TEST_V1.6.html')

text_obj=MIMEText(email_body,'html','utf-8')
attach_file=MIMEText(open(html_file_path,'rb').read(),'base64','utf-8')
attach_file['Content-type']='application/octet-stream'
attach_file.add_header('Content-Disposition','attachment',filename=('gbk','','WX_API_TEST_V1.6.html'))

email_obj=MIMEMultipart()
email_obj.attach(text_obj)
email_obj.attach(attach_file)

email_obj['from']='1585662645@qq.com'   #发件人
email_obj['to']='1585662645@qq.com'     #收件人    显示作用，实际作用不大
email_obj['Cc']='1160244825@qq.com,hello@qq.com'  #抄送人  发送多人
email_obj['subject']='P5P6接口自动化测试报告' #标题


smtp=smtplib.SMTP()
smtp.connect("smtp.qq.com")
#邮箱授权码
smtp.login(user='1585662645@qq.com',password='apopyzilpdxnhfeh')
smtp.sendmail('1585662645@qq.com','1585662645@qq.com',email_obj.as_string())    #很关键
# smtp.sendmail('1585662645@qq.com',['1585662645@qq.com','hello@qq.com'],email_obj.as_string())
smtp.close()